package org.bookshare.validator.report;

import java.util.HashMap;
import java.util.Map;

import org.benetech.beans.error.ValidationError;
import org.benetech.collections.ListMap;
import org.bookshare.document.beans.DocumentSet;
import org.bookshare.document.beans.HasOPF;
import org.bookshare.document.beans.HasXML;
import org.jdom.Document;
import org.jdom.Element;
import org.springframework.util.Assert;

/**
 * An object which contains the aggregate of all validation and additional
 * parsing that takes place during processing. This object is passed to the
 * ReportEngine, to be turned into output to be presented to the user.
 * @author Reuben Firmin
 */
public final class ValidationMetadata {

    private final ListMap<Element, ValidationError> elementViolations =
        new ListMap<Element, ValidationError>();
    private final ListMap<Document, ValidationError>
        documentValidationErrors = new ListMap<Document, ValidationError>();
    private final Map<String, Exception> errorMap = new HashMap<String, Exception>();
    private final Map<String, Object> modelMap = new HashMap<String, Object>();
    private String name;
    private DocumentSet documentSet;

    /**
     * Default constructor.
     */
    public ValidationMetadata(String name) {
    	this.name = name;
    }

    /**
     * The contents of the original package file.
     * @return not null
     */
    public DocumentSet getDocumentSet() {
        return documentSet;
    }

    /**
     * A map of documents to general violations that were found.
     * @return not null
     */
    public ListMap<Document, ValidationError> getDocumentViolations() {
        return documentValidationErrors;
    }

    /**
     * A map of elements to violations that were found.
     * @return not null
     */
    public ListMap<Element, ValidationError> getElementViolations() {
        return elementViolations;
    }

    /**
     * A map of "context" to exceptions that occurred during processing.
     * @return not null
     */
    public Map<String, Exception> getExceptions() {
        return errorMap;
    }

    /**
     * A general model map, containing additional data structures which may
     * be added to the report. These typically are generated and added by
     * {@link ReportGenerator} instances.
     * @return not null
     */
    public Map<String, Object> getModelMap() {
        return modelMap;
    }

    /**
     * Set the document set.
     * @param documentSet not null
     */
    public void setDocumentSet(final DocumentSet documentSet) {
    	Assert.isTrue(documentSet instanceof HasOPF);
    	Assert.isTrue(documentSet instanceof HasXML);
        this.documentSet = documentSet;
    }

    /**
     * The name of the report.
     * @return never null
     */
    public String getName() {
    	return this.name;
    }

}
